/**
 * 光闸模拟程序，需要 node-v8.5.0 以上
 */
const fs = require('fs');

const inRequestPath = 'F:/ftp/in/request';
const inResponsePath = 'F:/ftp/in/response';
const inRequestBackPath = inRequestPath + '/unimas_back';
const outRequestPath = 'F:/ftp/out/request';
const outResponsePath = 'F:/ftp/out/response';
const outResponseBackPath = outResponsePath + '/unimas_back';

if (! fs.existsSync(inRequestBackPath)){
  fs.mkdirSync(inRequestBackPath);
}
if (! fs.existsSync(outResponseBackPath)){
  fs.mkdirSync(outResponseBackPath);
}

setInterval(()=>{
  let list = fs.readdirSync(inRequestPath);
  for(let file of list){
    if (file !== 'unimas_back'){
      console.log('移动 request ：' + file);
      let srcFile = inRequestPath + '/' + file
      fs.copyFileSync(srcFile, inRequestBackPath + '/' + file);
      fs.renameSync(srcFile, outRequestPath + '/' + file);
    }
  }
  list = fs.readdirSync(outResponsePath);
  for(let file of list){
    if (file !== 'unimas_back'){
      console.log('移动 response ：' + file);
      let srcFile = outResponsePath + '/' + file
      fs.copyFileSync(srcFile, outResponseBackPath + '/' + file);
      fs.renameSync(srcFile, inResponsePath + '/' + file);
    }
  }
}, 3000);
